package com.changpay.zywy.ui.activity.count

import android.content.Intent
import com.changpay.zywy.R

import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.ui.dialog.SelectCountTypeDialog
import kotlinx.android.synthetic.main.activity_count_select.*
import kotlinx.android.synthetic.main.activity_finish_account.*
import kotlinx.android.synthetic.main.title_layout.*
import org.jetbrains.anko.sdk27.coroutines.onClick


class CountSelectActivity : BaseActivity() {

    private var dialogClickListener: SelectCountTypeDialog.OnDialogClickListener? = null
    override fun attachLayoutRes(): Int {
        return R.layout.activity_count_select
    }

    override fun initData() {
    }


    override fun initView() {
        tv_title.text = "数据统计"
        val gc_id = intent.getStringExtra("gc_id")
        iv_back.onClick { finish() }
        tv_count_select_total.onClick { showSelectDialog(0)
        }
        tv_count_select_trend.onClick { showSelectDialog(1) }
        tv_count_select_action.onClick { showSelectDialog(2) }
        tv_count_select_trade.onClick { showSelectDialog(3) }
        tv_count_select_new_sta.onClick { showSelectDialog(4) }
        tv_count_select_tai_jun_tong.setOnClickListener {
            Intent(this, CountTaiJunFirstActivity::class.java).run {
                putExtra("gc_id", gc_id)
                startActivity(this)
            }
        }

        dialogClickListener = SelectCountTypeDialog.OnDialogClickListener { v, type ->
            when (type) {
                0 -> Intent(this, CountTotalActivity::class.java).run {
                    putExtra("type", 1)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                1 -> Intent(this, CountTotalActivity::class.java).run {
                    putExtra("type", 2)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                2 -> Intent(this, CountTotalActivity::class.java).run {
                    putExtra("type", 3)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                3 -> Intent(this, CountTrendActivity::class.java).run {
                    putExtra("type", 1)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                4 -> Intent(this, CountTrendActivity::class.java).run {
                    putExtra("type", 2)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                5 -> Intent(this, CountTrendActivity::class.java).run {
                    putExtra("type", 3)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                6 -> Intent(this, CountActionTotalNewActivity::class.java).run {
                    putExtra("type", 1)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                7 -> Intent(this, CountActionMonthActivity::class.java).run {
                    putExtra("type", 2)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                8 -> Intent(this, CountTrandMonthActivity::class.java).run {
                    putExtra("type", 1)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                9 -> Intent(this, CountShopTrandActivity::class.java).run {
                    putExtra("type", 2)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                10 -> Intent(this, CountQuDaoTrandActivity::class.java).run {
                    putExtra("type", 3)
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                11 -> Intent(this, CountAddShopActivity::class.java).run {
                    putExtra("type", "shop")
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
                12 -> Intent(this, CountAddShopActivity::class.java).run {
                    putExtra("type", "member")
                    putExtra("gc_id", gc_id)
                    startActivity(this)
                }
            }
        }
    }

    override fun start() {
    }

    private fun showSelectDialog(type: Int) {

        val builder = SelectCountTypeDialog.Builder(this)
        builder.setType(type).setOnDialogClickListener(dialogClickListener)
        val build = builder.build<SelectCountTypeDialog>()
        build.show(supportFragmentManager)
    }


}
